﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyWPF.Models.Journal
{
    public interface IJournal
    {

        /// <summary>
        /// 创建日志数据库
        /// </summary>
        /// <param name="path"></param>
        /// <param name="datasource"></param>
        void CreateJournal(string path, string datasource);

        /// <summary>
        /// 在数据库里添加一张表
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        void CreateTable(string name, string type);

        /// <summary>
        /// 往表里添加一条日志
        /// </summary>
        /// <param name="table">表名</param>
        /// <param name="dateTime">时间</param>
        /// <param name="content">内容</param>
        /// <param name="type">类型</param>
        /// <param name="user">用户</param>
        /// <param name="addTips">是否提醒用户</param>
        void AddJournal(JournalContext journal);

        /// <summary>
        /// 读取日志数量
        /// </summary>
        /// <returns></returns>
        int ReadCount();

        /// <summary>
        /// 读取日志数量
        /// </summary>
        /// <returns></returns>
        int ReadCount(string value);

        /// <summary>
        /// 查找所有表内容
        /// </summary>
        /// <returns></returns>
        DataTable ReadJournal();

        /// <summary>
        /// 读最新的数据
        /// </summary>
        /// <returns></returns>
        /// <param name="num">数据条数</param>
        DataTable ReadJournal(int num);

        /// <summary>
        /// 查找指定区间日志并将日志返回为DataTable
        /// </summary>
        /// <param name="startnum">起始位</param>
        /// <param name="num">查询数量</param>
        /// <returns></returns>
        DataTable ReadJournal(int startnum, int num);

        /// <summary>
        /// 带value限制查找指定区间日志并将日志返回为DataTable
        /// </summary>
        /// <param name="startnum"></param>
        /// <param name="num"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        DataTable ReadJournal(int startnum, int num, string value);

        /// <summary>
        /// 清空表数据
        /// </summary>
        /// <returns></returns>
        bool DeleteJournal();

        /// <summary>
        /// 删除指定时间区间的数据
        /// </summary>
        /// <param name="starttime"></param>
        /// <param name="endtime"></param>
        bool DeleteJournal(DateTime starttime, DateTime endtime);

        /// <summary>
        /// 删除指定属性等于指定值的数据
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        bool DeleteJournal(string attribute, string value);
        /// <summary>
        /// 带value限制删除数据
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        bool DeleteJournal(string value);
    }

    public class JournalContext
    {
        /// <summary>
        /// 日志产生时间
        /// </summary>
        public DateTime Time { get; set; }

        /// <summary>
        /// 日志内容
        /// </summary>
        public string Context { get; set; }

        /// <summary>
        /// 日志类型
        /// </summary>
        public JournalType Type { get; set; }

        /// <summary>
        /// 用户
        /// </summary>
        public string User { get; set; }

        /// <summary>
        /// 是否提醒
        /// </summary>
        public bool AddTips { get; set; }
    }
    public enum JournalType
    {
        日志,
        报警,
        测试
    }
}
